import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

import { ServerHttp } from '../../providers/server-http/server-http';
/**
 * Generated class for the HttpTestPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
    selector: 'page-http-test',
    templateUrl: 'http-test.html',
})
export class HttpTestPage {

    private url: string[] = [
        './assets/test.json',
        '/upload/sql.json'
    ];
    constructor(public navCtrl: NavController, public navParams: NavParams, public http: ServerHttp) {
    }

    ionViewDidLoad() {
        console.log('ionViewDidLoad HttpTestPage');
    }

    load(index: number) {
        if (index == 0) {
            this.http.get(this.url[index]).subscribe((rs) => {
                console.log(rs);
                console.log(rs.json());
            }, (err) => {
                console.log(err);
            });
        } else {
            this.http.httpGetNoAuth(this.url[index]).subscribe((rs) => {
                console.log(rs);
            }, (err) => {
                console.log(err);
            });
        }
    }
}
